Django—常见问题解决
让Django项目运行允许外部访问
1.将python manage.py runserver 改为 python manage.py runserver 0.0.0.0:80 或者 python manage.py runserver 0.0.0.0:8000
2.在你的Django项目的settings.py中设置:ALLOWED_HOSTS = ["*"] 或者ALLOWED_HOSTS = ["*",]
3.通过你的ip地址来访问你的网址。如:http://49.232.56.69:8000/
报错:django.core.exceptions.ImproperlyConfigured: mysqlclient 1.3.13 or newer is required; you have 0.9.3.
1.找到安装包Django目录下的base.py文件:Python36\Lib\site-packages\django\db\backends\mysql\base.py文件,将文件中的如下两行代码注释:
if version < (1, 3, 13): raise ImproperlyConfigured('mysqlclient 1.3.13 or newer is required; you have %s.' % Database.__version__)
2.然后再进行数据库迁移操作。重新在项目manage.py路径下执行如下命令即可
[root@localhost study_django]# python manage.py makemigrations [root@localhost study_django]# python manage.py migrate
如果还有问题,比如出现了以下问题:
File "D:\Program Files\Python36\Lib\site-packages\django\db\backends\mysql\operations.py", line 146, in last_executed_query
query = query.decode(errors='replace')
AttributeError: 'str' object has no attribute 'decode',
打开operations.py文件,146行中的decode改为encode即可。
Django解决跨域问题
https://blog.csdn.net/dangbai01_/article/details/85094883
https://blog.csdn.net/bbwangj/article/details/74502967
https://blog.csdn.net/shanliangliuxing/article/category/1351171
https://www.cnblogs.com/daofaziran/p/9463273.html
https://www.cnblogs.com/linxiyue/category/569717.html
https://www.cnblogs.com/mashuqi/p/11576705.html
https://www.cnblogs.com/midworld/p/10996850.html
https://www.cnblogs.com/ftl1012/tag/Django%E5%AD%A6%E4%B9%A0/